package com.bluestone.scripts;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import com.bluestone.util.Util;

public class ProjectTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		generateIVRProject();
	}
	
	public static void generateIVRProject(){
		try {
			Project project = new Project();
			project.setVersion("7.0.0");
			project.setName("AIVR");
			project.setLanguage("en");
			project.setCountry("US");
			
			Resource resource = new Resource();
			resource.setKey("vd");
			resource.setName("voicedialog");
			project.addResource(resource);
			
			Input input = new Input();
			input.setFile("scripts\\aivr_voexo_scripts.xml");
			
			Input input1 = new Input();
			input1.setFile("scripts\\aivr_callflow.xml");
			
			project.addInput(input);
			project.addInput(input1);
			
			Execute execute = new Execute();
			execute.setFile("scripts\\aivr_voexo_scripts.xml");
			project.addExecute(execute);

			
			JAXBContext context = JAXBContext.newInstance(project.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty("jaxb.formatted.output",new Boolean(true));
			
			// create parent folder if it doesn't exist to avoid IOException
			String path =  "./scripts/aivr.xml";
			File file = new File(path);
			if ( file.getParentFile()!=null && !file.getParentFile().exists() ) {
				file.getParentFile().mkdirs();
			}	
			marshaller.marshal(project, file);
			
		}catch(Exception me) {
			Util.getLogger().error("fail to save project"+me);
		}
	}
	public static void generateProject(){
		try {
			Project project = new Project();
			project.setName("test");

			
			JAXBContext context = JAXBContext.newInstance(project.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty("jaxb.formatted.output",new Boolean(true));
			
			// create parent folder if it doesn't exist to avoid IOException
			String path =  "./scripts/project.xml";
			File file = new File(path);
			if ( file.getParentFile()!=null && !file.getParentFile().exists() ) {
				file.getParentFile().mkdirs();
			}	
			marshaller.marshal(project, file);
			
		}catch(Exception me) {
			Util.getLogger().error("fail to save project"+me);
		}			
	}

}
